

var o = require("MtilsJS"),
    i = cc.Class({
        // extends: cc.Component,
        properties: {
            game_name: "",
            game_id: "",
            token_seed: "",
            msg_type_other: 10,
            msg_type_login: 11,
            msg_type_get: 12,
            msg_type_post: 13,
            msg_type_append: 14,
            msg_type_logout: 15,
            msg_type_unknow: 16,
            msg_max_len: 2048
        },
        ctor: function (t, e) {
            this.game_name = t, this.game_id = e;
        },
        SetTokenSeed: function (t) {
            this.token_seed = t;
        },
        GetTokenSeed: function () {
            return this.token_seed;
        },
        GetUtcStamp: function () {
            var t = String(Date.parse(new Date()));
            return Number(t.substr(0, t.length - 3));
        },
        GetUtcMillisecondStamp: function () {
            return new Date().getTime();
        },
        CalMsgId: function (t) {
            var e = Math.floor(9e3 * Math.random() + 1e3),
                n = o.hex_md5(t).substr(0, 4);
            return this.GetUtcStamp() + this.game_name.substr(0, 4) + n + e;
        },
        CalLoginKey: function (t) {
            var e = String(this.game_id) + String(t) + String(this.game_id),
                n = o.hex_md5(e);
            return n.substr(3 * n.length / 4, n.length / 4);
        },
        CalTokenKey: function (t) {
            return o.hex_md5(this.token_seed + this.game_id + t).substr(4, 8);
        },
        CalPlayerEncryptId: function (t) {
            return o.hex_md5(t).substr(0, 12);
        },
        CalCheckKey: function (t) {
            var e;
            return e = o.hex_sha256(t), e = o.hex_sha1(e), (e = o.hex_md5(e)).substr(8, 8);
        },
        GetLoginRequestStr: function (t) {
            var e = this.CalMsgId(t),
                n = {
                    loginKey: this.CalLoginKey(e),
                    gameId: this.game_id,
                    msgId: e,
                    timeStamp: this.GetUtcStamp(),
                    msgType: this.msg_type_login
                };
            return JSON.stringify(n);
        },
        GetGetValRequestStr: function (t, e) {
            if (this.token_seed.length < 4) return "";
            var n = this.CalMsgId(t),
                o = this.CalTokenKey(n),
                i = {
                    userId: this.CalPlayerEncryptId(t),
                    dataKey: String(e)
                },
                a = {
                    tokenKey: o,
                    gameId: this.game_id,
                    msgId: n,
                    timeStamp: this.GetUtcStamp(),
                    msgType: this.msg_type_get,
                    content: i
                };
            return JSON.stringify(a);
        },
        GetGetOpenidValRequestStr: function (t, e, n) {
            if (this.token_seed.length < 4) return "";
            var o = this.CalMsgId(t),
                i = this.CalTokenKey(o),
                a = {
                    userId: this.CalPlayerEncryptId(t),
                    openId: n,
                    dataKey: String(e)
                },
                s = {
                    tokenKey: i,
                    gameId: this.game_id,
                    msgId: o,
                    timeStamp: this.GetUtcStamp(),
                    msgType: this.msg_type_get,
                    content: a
                };
            return JSON.stringify(s);
        },
        GetPostValRequestStr: function (t, e, n) {
            if (this.token_seed.length < 4) return "";
            var o = this.CalMsgId(t),
                i = this.CalTokenKey(o),
                a = this.CalPlayerEncryptId(t),
                s = {
                    userId: a,
                    dataKey: String(e),
                    dataVale: String(n)
                },
                c = a + String(e) + String(n),
                r = {
                    tokenKey: i,
                    gameId: this.game_id,
                    msgId: o,
                    timeStamp: this.GetUtcStamp(),
                    msgType: this.msg_type_post,
                    content: s,
                    checkKey: this.CalCheckKey(c)
                };
            return JSON.stringify(r);
        },
        GetPostAppendValRequestStr: function (t, e, n) {
            if (this.token_seed.length < 4) return "";
            var o = this.CalMsgId(t),
                i = this.CalTokenKey(o),
                a = this.CalPlayerEncryptId(t),
                s = {
                    userId: a,
                    dataKey: String(e),
                    dataVale: String(n)
                },
                c = a + String(e) + String(n),
                r = {
                    tokenKey: i,
                    gameId: this.game_id,
                    msgId: o,
                    timeStamp: this.GetUtcStamp(),
                    msgType: this.msg_type_append,
                    content: s,
                    checkKey: this.CalCheckKey(c)
                };
            return JSON.stringify(r);
        },
        GetPostShareAppendValRequestStr: function (t, e, n, o) {
            if (this.token_seed.length < 4) return "";
            var i = this.CalMsgId(t),
                a = this.CalTokenKey(i),
                s = this.CalPlayerEncryptId(e),
                c = {
                    userId: s,
                    dataKey: String(n),
                    dataVale: String(o)
                },
                r = s + String(n) + String(o),
                l = {
                    tokenKey: a,
                    gameId: this.game_id,
                    msgId: i,
                    timeStamp: this.GetUtcStamp(),
                    msgType: this.msg_type_append,
                    content: c,
                    checkKey: this.CalCheckKey(r)
                };
            return JSON.stringify(l);
        },
        GetUserInfoJsonStr: function (t, e, n) {
            var i = {
                openId: this.CalPlayerEncryptId(t),
                nickName: o.base64_encode(e),
                avatarUrl: o.base64_encode(n)
            };
            return JSON.stringify(i);
        }
    });
module.exports = i